﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using TaskProject.Application.Command.BOM;
using TaskProject.Domain.BOM;
using TaskProject.ErrorCode;
using TaskProject.Extension;

namespace TaskProject.Controllers
{
    /// <summary>
    /// BOM管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BOMController : ControllerBase
    {
        IMediator mediator;

        public BOMController(IMediator mediator)
        {
            this.mediator = mediator;
        }
       /// <summary>
       /// 查询BOM
       /// </summary>
       /// <param name="request"></param>
       /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<BOMDTO>>> GetBOM([FromQuery]GetBOMCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 新增BOM
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> AddBOM(AddBOMCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 查询物料
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<MaterialModel>>> GetMaterial([FromQuery]GetMaterialCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 查询产品
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<ProductModel>>> GetProduct([FromQuery]GetProductCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 编辑BOM
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> UpdateBOM(UpdateBOMCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 查询单个BOM 根据ProductId
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<BOMModel>>> GetBOMOne([FromQuery]GetBOMOneCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 删除BOM
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> DelBOM(DelBOMCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 查询单个BOM 根据BOMId
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<BOMDTO>> GetOneBOM([FromQuery]GetOneBOMCommand request)
        {
            return  mediator.Send(request);
        }
        /// <summary>
        /// 工艺
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<CraftModel>>> GetCraft([FromQuery]GetCraftCommand request)
        {
            return mediator.Send(request);
        }
    }
}
